package com.example.demo.config.security;

import com.baomidou.mybatisplus.annotation.TableName;
import com.example.demo.bean.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;


@TableName("user")
@Data
public class LoginUser implements UserDetails {

    private User user;

    /**
     * 返回用户的角色/权限
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of();
    }


    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    /**
     * 账户是否没有过期，返回true代表正常
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return user.getAccountNonExpired();
    }
    /**
     * 账户是否没有锁定，返回true代表正常
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return user.getAccountNonLocked();
    }
    /**
     * 密码是否没有过期，返回true代表正常
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return user.getCredentialsNonExpired();
    }
    /**
     * 账户是否可用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return user.getEnabled();
    }
}
